<template>
  <div class="home">
    <van-swipe class="my-swipe" :autoplay="3000" indicator-color="white">
      <van-swipe-item v-for="item in bannerList" :key="item.id">
        <img :src="item.picUrl" />
      </van-swipe-item>
    </van-swipe>
    <div class="sec">
      <div class="sec-top">商品列表</div>
      <div class="sec-box">
        <div class="sec-main" v-for="item in shopsList" :key="item.id">
          <div class="main-img">
            <img :src="item.pic" />
          </div>
          <div class="main-text">
            {{ item.characteristic }}
          </div>
          <div class="main-pricelist">
            <div class="main-price">
              <div class="price-lfet">
                <div class="price-yi">￥</div>
                <div class="price-er">{{ item.minPrice }}</div>
              </div>
              <div class="price-right">￥{{ item.originalPrice }}</div>
            </div>
            <div class="mian-but">购买</div>
          </div>
        </div>
      </div>
    </div>
  </div>
</template>

<script lang="ts" setup>
import request from "../utils/request"
import { onMounted, ref } from "vue"

let bannerList = ref<any>([])//轮播图列表
let shopsList = ref<any>([])


// 获取轮播图列表
function getBannerList() {
  request({
    url: "banner/list"
  }).then((res: any) => {
    // console.log(res);
    if (res.code === 0) {
      bannerList.value = res.data
    }
  })
}

// 获取商品列表
function getShopsList() {
  request({
    url: "shop/goods/list/v2",
    method: "post"
  }).then((res: any) => {
    console.log(res);
    shopsList.value = res.data.result
  })
}

onMounted(() => {
  getBannerList()
  getShopsList()
})
</script>
<style scoped lang="scss">
.my-swipe .van-swipe-item {
  img {
    width: 375px;
    height: 180px;
  }
}

.sec-top {
  width: 375px;
  height: 50px;
  line-height: 50px;
  text-align: center;
  font-size: 16px;
  color: #323233;
  background-color: #fff;
}

.sec-top:before,
.sec-top::after {
  content: "";
  display: inline-block;
  width: 20px;
  height: 6px;
  background-image: url(https://v-shop.shuzp.top/v2/assets/img/line_askew.225cce63.png);
  background-size: 100% 100%;
  background-repeat: no-repeat;
  margin: 0 7px;
}

.sec-box {
  width: 375px;
  display: flex;
  justify-content: space-around;
  flex-wrap: wrap;
}

.sec-main {
  width: 187.5px;
  height: 273px;
}

.main-img {
  width: 172.5px;
  height: 172.5px;
  margin: 0 auto;
}

.main-img img {
  width: 172.5px;
  height: 172.5px;
}

.main-text {
  width: 169px;
  height: 40px;
  margin: 0 auto;
  margin-top: 8px;
  font-size: 15px;
  line-height: 1.3;
  overflow: hidden;
}

.main-pricelist {
  display: flex;
  width: 167px;
  height: 27px;
  margin: 0 auto;
  margin-top: 5px;
  justify-content: space-between;
}

.main-price {
  width: 56px;
  display: flex;
  align-items: center;
}

.price-lfet {
  // width: 21px;
  display: flex;
  align-items: center;
}

.price-yi {
  font-size: 13px;
  color: #1ba784;
}

.price-er {
  font-size: 20px;
  color: #1ba784;
}

.price-right {
  font-size: 13px;
  color: #969799;
  text-decoration: line-through;
  margin-left: 2px;
}

.mian-but {
  width: 45px;
  height: 24px;
  border: #1ba784 1px solid;
  font-size: 14px;
  line-height: 27px;
  text-align: center;
  color: #1ba784;
}
</style>
